package CodingTest;
import java.util.HashSet;
import java.util.Set;
public class Hashsettest{
   public static void main(String[] args){
      Set<String> set1 = new HashSet<>();
      //向set1中添加元素：set.add()
      //计算集合的大小：set.size()
      set1.add("London");
      set1.add("paris");
      set1.add("New York");
      set1.add("San Francisco");
      set1.add("Beijing");
      System.out.println("set1 is" + set1);
      System.out.println(set1.size() + "elements in set1");
      //删除集合中的一个元素：set.remove()
      set1.remove("London");
      System.out.println("\nset1 is "+set1);
      System.out.println(set1.size() +"elements in set1");

      Set<String> set2 = new HashSet<>();
      set2.add("London");
      set2.add("Shanghai");
      set2.add("Paris");
      System.out.println("\nset2 is "+set2);
      System.out.println(set2.size() + "elements in set2");
      //set.contains() 集合中是否包含元素值，
      System.out.println("\nIs Taipei in set2?" + set2.contains("Taipei"));
      //set1.retrinAll(set2) 保留和set1共有的元素
   }
}
